package com.melodyframe.stage.web.context;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.melodyframe.common.context.ContextLocal;

public class RequestContextLocal {
	private static ThreadLocal<RequestContext>	localRequestContext	= new ThreadLocal<>();

	public static RequestContext getContext() {
		RequestContext context = localRequestContext.get();
		if (null == context) {
			context = new RequestContext();
			localRequestContext.set(context);
		}
		return context;
	}

	public static RequestContext bind(HttpServletRequest request,
			HttpServletResponse response) {
		RequestContext context = getContext();
		context.setRequest(request);
		context.setResponse(response);
		ContextLocal.put("request", context);
		return context;
	}
}
